package javabase.schoolwork.day6_10;

/**
 * @author fance
 * @date 2018/6/10 9:23
 */
class TicketThreadI implements Runnable {
    private int ticket = 80;

    @Override
    public  void run() {
        synchronized (this) {
            for (int i = 0; i < 100; i++) {
                sale();
            }
        }

    }
    public  void  sale() {
        if (ticket > 0) {
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() +
            "卖票 " + ticket--);
        }
    }
}
public class TicketDemo {
    public static void main(String[] args) {
        TicketThreadI ticketThreadI = new TicketThreadI();
        new Thread(ticketThreadI).start();
        new Thread(ticketThreadI).start();
        new Thread(ticketThreadI).start();
    }
}
